﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using OilRigSumoWrestlers.KeyBindings;
using OilRigSumoWrestlers.Scenes.Menu;
using RaptorEngine;
using RaptorEngine.Components;
using RaptorEngine.Managers;

namespace OilRigSumoWrestlers.Controllables
{
    public class SplashScreenController : Controllable
    {
        public SplashScreenController(Entity entity) : base(entity)
        {
        }
        public override void Update(GameTime time)
        {
            if (GameEngine.Instance.Input.IsPressed(Keys.Enter))
            {
                SetBindings();
            }
            else if (GameEngine.Instance.Input.IsPressed(Keys.Escape) || GameEngine.Instance.Input.IsPressed(Buttons.B, LogicalPlayerIndex.Any))
            {
                GameEngine.Instance.Exit();
            }
            else
            {
                if (GameEngine.Instance.Input.IsPressed(Buttons.A, PlayerIndex.One))
                {
                    GameEngine.Instance.Input.SetLogicalPlayer(LogicalPlayerIndex.One, PlayerIndex.One);
                    SetBindings();
                }
                else if (GameEngine.Instance.Input.IsPressed(Buttons.A, PlayerIndex.Two))
                {
                    GameEngine.Instance.Input.SetLogicalPlayer(LogicalPlayerIndex.One, PlayerIndex.Two);
                    SetBindings();
                }
                else if (GameEngine.Instance.Input.IsPressed(Buttons.A, PlayerIndex.Three))
                {
                    GameEngine.Instance.Input.SetLogicalPlayer(LogicalPlayerIndex.One, PlayerIndex.Three);
                    SetBindings();
                }
                else if (GameEngine.Instance.Input.IsPressed(Buttons.A, PlayerIndex.Four))
                {
                    GameEngine.Instance.Input.SetLogicalPlayer(LogicalPlayerIndex.One, PlayerIndex.Four);
                    SetBindings();
                }
            }
        }

        private void SetBindings()
        {
            new PlayerMenuBindings(LogicalPlayerIndex.One).ActivateBindings();
            new PlayerBindings(LogicalPlayerIndex.One).ActivateBindings();
            GoForwards();
        }

        protected void GoForwards()
        {
            GameEngine.Instance.Scene.HideCurrentScene();
            GameEngine.Instance.Scene.StopCurrentScene();
            GameEngine.Instance.Scene.PushScene(new MainMenu());
            GameEngine.Instance.Scene.StartCurrentScene();
            GameEngine.Instance.Scene.ShowCurrentScene();
        }
    }
}
